package designpattern.compoundPattern;

/**
 * Created by asus on 2017/11/2.
 */
public class DuckSimulator{
    public static void main(String[] args) {
        DuckSimulator simulator=new DuckSimulator();
        AbstractDuckFactory duckFactory=new CountingDuckFactory();
        simulator.simulate(duckFactory);
    }
    void simulate(AbstractDuckFactory duckFactory){
        Quackable mallardDuck=duckFactory.createMallardDuck();
        Quackable redHeadDuck = duckFactory.createRedHeadDuck();
//        Quackable duckCall = duckFactory.createDuckCall();
//        Quackable rubberDuck = duckFactory.createRubberDuck();
//
        Flock flockOfDucks =new Flock();
        flockOfDucks.add(mallardDuck);
        flockOfDucks.add(redHeadDuck);
//        flockOfDucks.add(duckCall);
//        flockOfDucks.add(rubberDuck);
//        flockOfDucks.add(gooseDuck);

        Flock flockOfMallards = new Flock();
        Quackable mallardOne=duckFactory.createMallardDuck();
        Quackable mallardTwo=duckFactory.createMallardDuck();

        flockOfMallards.add(mallardOne);
        flockOfMallards.add(mallardTwo);

        Quacklogist quacklogist=new Quacklogist();
        flockOfDucks.add(flockOfMallards);
        flockOfDucks.registerObserver(quacklogist);

//        System.out.println("\nDuck Simulator: Whole Flock simulation");
//        simulate(flockOfDucks);

//        System.out.println("\nDuck Simulator: Mallard Flock Simulation");
        simulate(flockOfDucks);

        System.out.println("The ducks quacked  "+QuackCounter.getQuacks()+"  times");

    }

    void simulate(Quackable duck){
        duck.quack();
    }

}
